<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>键盘事件修饰符</title>
</head>
<body>
<div id="app">
    <!--<form action="#">-->
    <label for="username">用户名</label><input type="text" name="username" id="username" v-on:keyup="keyup">

    <!--</form>-->

    <form action="#">
        <label for="username">用户名</label><input type="text" name="username" id="pass" v-on:keypress="keypress">

    </form>

    <!--<form action="#">-->
    <label for="nameid">用户名</label><input type="text" name="nameid" id="passit" v-on:keyup.enter="keyenter">

    <!--</form>-->
</div>

<script type="module">
    import {createApp} from "../../../js/vue.esm-browser.js";

    let app = createApp(
        {
            setup() {
                function keyup(event) {
                    /*console.log(event);
                    // 注意：不能在 函数中访问 元素
                    let element = document.querySelector("#username");
                    console.log(element.value);*/
                    event.preventDefault()
                    if (event.key === "Enter") {

                        let element = document.querySelector("#username");
                        console.log(element.value);
                    }
                }

                function keypress(event) {
                    /*console.log(event);
                    // 注意：不能在 函数中访问 元素
                    let element = document.querySelector("#username");
                    console.log(element.value);*/

                    if (event.key === "Enter") {
                        event.preventDefault()
                        let element = document.querySelector("#pass");
                        console.log(element.value);
                    }
                }

                function keyenter(event) {
                    let element = document.querySelector("#passit");
                    console.log(element.value);
                    // event.preventDefault()
                }

                return {keyup, keypress, keyenter}
            }
        }
    );

    app.mount("#app")
</script>
</body>
</html>